package com.LC.DAO;

import com.LC.Entity.CheckGroup;
import com.LC.Entity.CheckItem;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CheckGroupDAO {

    @Select("select * from t_checkitem")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "code",property = "code"),
            @Result(column = "name",property = "name"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "age",property = "age"),
            @Result(column = "price",property = "price"),
            @Result(column = "type",property = "type"),
            @Result(column = "attention",property = "attention"),
            @Result(column = "remark",property = "remark")
    })
    public List<CheckItem> showAll();

    @Select("<script>"+
            "select * from t_checkgroup" +
            "<if test = 'value != null and value.length > 0'>" +
            "where code = #{value} or name = #{value} or helpCode = #{value}"+
            "</if>" +
            "</script>")
    public Page<CheckGroup> findPage(String queryString);

    @Insert("insert into t_checkgroup(code,name,helpCode,sex,remark,attention) values (#{code},#{name}," +
            "#{helpCode},#{sex},#{remark},#{attention})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id") //获取自动生成的id并封装到bean的id属性中
    public void addCheckGroup(CheckGroup checkGroup);

    @Insert("insert into t_checkgroup_checkitem(checkgroup_id,checkitem_id) values (#{groupId},#{itemId})")
    public void addMiddleTableCheckGroupAndCheckItem(@Param("groupId") int groupId, @Param("itemId") int itemId);

    @Select("select * from t_checkgroup where id = #{CheckGroupId}")
    public CheckGroup findCheckGroupById(Integer CheckGroupId);

    @Select("select checkitem_id from t_checkgroup_checkitem where checkgroup_id = #{CheckGroupId}")
    public List<Integer> IncludeIds(Integer CheckGroupId);

    @Update("update t_checkgroup set code = #{code}, name = #{name},helpCode = #{helpCode}," +
            "sex = #{sex},remark = #{remark},attention = #{attention} where id = #{id}")
    public void updateCheckGroup(CheckGroup checkGroup);

    @Update("update t_checkgroup_checkitem set checkitem_id = #{itemId} where checkgroup_id = #{groupId}")
    public void updateIncludedItemIds(@Param("groupId") Integer groupId, @Param("itemId") Integer itemId);

    @Delete("delete from t_checkgroup_checkitem where checkgroup_id = #{groupId}")
    public void deleteMiddleGroupById(int groupId);

    @Delete("delete from t_checkgroup where id = #{groupId}")
    public void deleteCheckGroupById(int groupId);




}
